package com.fr.web.face;

import com.fr.base.CodeUtils;
import com.fr.base.FRContext;
import com.fr.base.file.ConfigManager;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.privilege.authentication.Authentication;
import com.fr.privilege.filter.core.TemplateAccessDealWith;
import com.fr.report.parameter.Parameter;
import javax.servlet.http.HttpServletRequest;

public class WriteReportletDef extends AbstractNodeDef
{
  private ReportletInfo reportletInfo;

  public ReportletInfo getReportletInfo()
  {
    return this.reportletInfo;
  }

  public void setReportletInfo(ReportletInfo paramReportletInfo)
  {
    this.reportletInfo = paramReportletInfo;
  }

  public Access createURI(HttpServletRequest paramHttpServletRequest, Authentication paramAuthentication)
  {
    int j;
    if (this.reportletInfo == null)
      return new Access("", false);
    if ((paramAuthentication != null) && (!(TemplateAccessDealWith.hasLegalAccess(this.reportletInfo.getReporletPath(), 2, paramAuthentication))))
      return new Access("", false);
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append(FRContext.getConfigManager().getServletMapping()).append("?op=write");
    if (this.reportletInfo.getReporletPath() != null)
      localStringBuffer.append("&reportlet=").append(CodeUtils.encodeURIComponent(this.reportletInfo.getReporletPath()));
    int i = this.reportletInfo.getParameterCount();
    if (i > 0)
      for (j = 0; j < i; ++j)
      {
        localStringBuffer.append("&");
        Parameter localParameter = this.reportletInfo.getParameter(j);
        Object localObject = localParameter.getValue();
        if (localObject != null)
          localStringBuffer.append(CodeUtils.encodeURIComponent(localParameter.getName())).append("=").append(CodeUtils.encodeURIComponent(localParameter.valueToString()));
      }
    return new Access(CodeUtils.cjkEncode(localStringBuffer.toString()), true);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if ((paramXMLableReader.isChildNode()) && ("ReportletInfo".equals(paramXMLableReader.getTagName())))
    {
      ReportletInfo localReportletInfo = new ReportletInfo();
      paramXMLableReader.readXMLObject(localReportletInfo);
      setReportletInfo(localReportletInfo);
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    if (getReportletInfo() != null)
      getReportletInfo().writeXML(paramXMLPrintWriter);
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }
}